""" FuzzyVariable

This module implements a fuzzy variable and hedges.


2006 (C) Pollini Andrea

this file si released under LGPL license 2.0  ora above.
"""
__author__ = "Pollini Andrea  nelson1977@gmail.com"


import MembershipFunctions

class FuzzyVariable(object):
    
    
    
    def __init__(self, name):
        self.name = name
        self.member_functions = {}
        
        
    def add(self, aMemFunction):
        self.member_functions[ aMemFunction.name ] = aMemFunction
        
    
    def __call__(self, aCrisp):
        membership_vec = {}
        for mf_name,mf in self.member_functions.items():
            membership_vec[ mf_name ] = mf(aCrisp)
            
        return membership_vec
    
    
if __name__ == '__main__':
    fv  = FuzzyVariable("prova")
    fv.add(MembershipFunctions.make_membership_function("TRIANGULAR","prova1",values=[0,1.2,2.5]))
    fv.add(MembershipFunctions.make_membership_function("TRIANGULAR","prova2",values=[1,2.2,3.5]))
    fv.add(MembershipFunctions.make_membership_function("TRIANGULAR","prova3",values=[3,4.2,5]))
    
    print fv(1), fv(2),fv(3),fv(4),fv(5)